package com.example.team.service.Imp;

import com.example.team.dao.ISafetyEquipmentPurchaseDateDao;
import com.example.team.entity.SafetyEquipmentPurchaseDate;
import com.example.team.service.ISafetyEquipmentPurchaseDateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 编写者：蓝江富
 * 时间：2023年10月31日18:40:57
 */
//服务接口规范的方法实现
@Service
public class ISafetyEquipmentPurchaseDateServiceImpl implements ISafetyEquipmentPurchaseDateService {

    @Autowired
    private ISafetyEquipmentPurchaseDateDao safetyEquipmentPurchaseDateMapper;
    @Override
    public int insertSafetyEquipmentPurchaseDate(SafetyEquipmentPurchaseDate safetyEquipmentPurchaseDate) {
        //设置成功状态
        int safetyEquipmentPurchaseDateValue;
        SafetyEquipmentPurchaseDate safetyEquipmentPurchaseDate1=new SafetyEquipmentPurchaseDate();
        safetyEquipmentPurchaseDate1.setPurchaseDateId(safetyEquipmentPurchaseDate.getPurchaseDateId());
        SafetyEquipmentPurchaseDate allSafetyEquipmentPurchaseDate=safetyEquipmentPurchaseDateMapper.getSafetyEquipmentPurchaseDateById(safetyEquipmentPurchaseDate1);
        if(allSafetyEquipmentPurchaseDate!=null){
            safetyEquipmentPurchaseDateValue = -1;
        }else {
            safetyEquipmentPurchaseDateValue= safetyEquipmentPurchaseDateMapper.insertSafetyEquipmentPurchaseDate(safetyEquipmentPurchaseDate);
        }
        //返回状态码
        return safetyEquipmentPurchaseDateValue;
    }

    @Override
    public int deleteSafetyEquipmentPurchaseDate(SafetyEquipmentPurchaseDate safetyEquipmentPurchaseDate) {
        //设置成功状态
        int safetyEquipmentPurchaseDateValue;
        SafetyEquipmentPurchaseDate safetyEquipmentPurchaseDate1=new SafetyEquipmentPurchaseDate();
        safetyEquipmentPurchaseDate1.setExaminer(safetyEquipmentPurchaseDate.getExaminer());
        List<SafetyEquipmentPurchaseDate> allSafetyEquipmentPurchaseDate=safetyEquipmentPurchaseDateMapper.getAllSafetyEquipmentPurchaseDate(safetyEquipmentPurchaseDate1);
        if(allSafetyEquipmentPurchaseDate.size()==0){
            safetyEquipmentPurchaseDateValue = -1;
        }else {
            safetyEquipmentPurchaseDateValue= safetyEquipmentPurchaseDateMapper.deleteSafetyEquipmentPurchaseDate(safetyEquipmentPurchaseDate);
        }
        //返回状态码
        return safetyEquipmentPurchaseDateValue;
    }

    @Override
    public int updateSafetyEquipmentPurchaseDate(SafetyEquipmentPurchaseDate safetyEquipmentPurchaseDate) {
        //设置成功状态
        int safetyEquipmentPurchaseDateValue;
        //通过主键id对数据更新，判断是否存在目标id
        SafetyEquipmentPurchaseDate safetyEquipmentPurchaseDate1=new SafetyEquipmentPurchaseDate();
        safetyEquipmentPurchaseDate1.setPurchaseDateId(safetyEquipmentPurchaseDate.getPurchaseDateId());
        SafetyEquipmentPurchaseDate allSafetyEquipmentPurchaseDate=safetyEquipmentPurchaseDateMapper.getSafetyEquipmentPurchaseDateById(safetyEquipmentPurchaseDate1);
        if(allSafetyEquipmentPurchaseDate==null){
            //如果为空，说明无法找到匹配的目标Id，设置状态码-1
            safetyEquipmentPurchaseDateValue = -1;
        }else {
            //否则执行更新数据库功能，同时赋值更新成功的数据数量到状态码
            safetyEquipmentPurchaseDateValue= safetyEquipmentPurchaseDateMapper.updateSafetyEquipmentPurchaseDate(safetyEquipmentPurchaseDate);
        }
        //返回状态码
        return safetyEquipmentPurchaseDateValue;
    }

    @Override
    public List<SafetyEquipmentPurchaseDate> getAllSafetyEquipmentPurchaseDate(SafetyEquipmentPurchaseDate safetyEquipmentPurchaseDate) {
        return safetyEquipmentPurchaseDateMapper.getAllSafetyEquipmentPurchaseDate(safetyEquipmentPurchaseDate);
    }

    @Override
    public SafetyEquipmentPurchaseDate getSafetyEquipmentPurchaseDate(SafetyEquipmentPurchaseDate safetyEquipmentPurchaseDate) {
        return safetyEquipmentPurchaseDateMapper.getSafetyEquipmentPurchaseDate(safetyEquipmentPurchaseDate);
    }
}
